from udp_discovery import UDPDiscoveryClient
import time
import json


if __name__ == '__main__':
    # 客户端示例
    def on_server_found(server_info, from_address):
        print(f"客户端发现服务器: {server_info['name']} (IP: {server_info['ip']}) 来自 {from_address}")
        print(json.dumps(server_info, ensure_ascii=False, indent=2))
    # 创建并启动UDP发现客户端
    client = UDPDiscoveryClient(
        port=40000,
        device_name="trackHostUI",
        broadcast_interval=5,
        on_server_discovered=on_server_found
    )
    client.start()
    client.start_broadcasting()
    while True:
        time.sleep(5)

